Layer 0 amendment: unified decomposition redesign spec (Phase R + T + B2)#74
Merged
StarGazerM merged 2 commits intoMay 19, 2026
Merged
Conversation
Introduces docs/phase_decomposition_redesign.md as the architectural layer above compiler_redesign.md. Frames every remaining migration PR against ONE load-bearing invariant: the ACID test (any new algorithm / pragma / index type / aggregation / backend target must be purely additive — zero edits to existing source files). Diagnoses three concrete violation classes with file:line citations (runner monolith ~57 imperative branches across orchestrator.py + complete_runner.py + runner.py; target leakage into IR via CUDA-shaped op names and LoweringCtx render fields; target monopolization in the pipeline shims and module-global plugin registry). Proposes the three-axis fix (Phase R Runner-IR, Phase T target abstraction, Phase B2 target parametricity), worked examples for both a new backend and a new algorithm, and a 35-PR migration plan that's byte-equivalence- gated on CUDA throughout. Supersedes the parked Phase A3 branches. Wires the new doc into docs/index.md (hidden toctree) and cross-links from docs/compiler_redesign.md per the existing F5 pattern. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Per user feedback: 35 PRs is too granular. The per-op decomposition
duplicated framework infrastructure across PRs and made rebases
noisy. Bundle by architectural concern instead:
PR-1 (~1500 LOC) Foundation: LowerCtx split + target parametricity
(Wave T1 + B2-1)
PR-2 (~2500 LOC) RIR framework + all 10 MIR→RIR lowerings
(Wave R1 + R2)
PR-3 (~3500 LOC) RIR renders + delete 2820 LOC of legacy monolith
(Wave R3 + Cleanup C-1)
PR-4 (~500 LOC) IIR rename (5-8 ops, mechanical)
(Wave T2)
PR-5 (~800 LOC) Index-plugin data/render split + Phase E
re-versioning (Wave T3)
PR-6 (~600 LOC) Multi-target + D20 discipline rule
(Wave B2-2 + Cleanup C-2)
Each PR is one architectural change, not one mechanical op. Per-PR
work envelope is ~1500-3500 LOC, comparable to the largest Phase B
PRs that shipped successfully. Byte-equivalence on CUDA remains the
per-PR safety net throughout.
Sequencing is strictly serial — PRs each touch broad swaths of the
codebase, so parallelism would cause significant merge conflicts.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
StarGazerM
marked this pull request as ready for review
May 19, 2026 18:25
3 tasks
StarGazerM
added a commit
that referenced
this pull request
May 19, 2026
…tch gaps) (#75) User review of merged PR #74 surfaced 8 places where the proposed RIR vocabulary still expressed operational meaning as string-tagged dispatch or implicit list ordering, in violation of the spec's own ACID test. This amendment fills them by promoting each concern to typed IR ops or typed metadata: 11 typed maintenance ops (replacing one MaintenanceCall with kind:str), typed TerminationCheck union, typed Step.deps DAG edges, typed DeltaVariantSet + VariantOrdering, typed MultiHeadInsert + HeadOrdering, three typed kernel-def ops (Count/Materialize/Fused replacing KernelDef.phase:str), typed ComposabilityMeta on Pragma, and typed ViewBinding carrier. RIR op count grows ~10 to 30; PR-2 splits to PR-2a + PR-2b; total ledger 6 to 7 PRs. D21 discipline (no string dispatch in renderer bodies) added. PR-1 scope unchanged. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Doc-only — 1238-line architectural spec that supersedes the piecemeal A3 cleanup with a unified attack on three decomposition problems under ONE ACID test.
ACID test (the new load-bearing invariant):
Today the redesign satisfies this for ~one slice of one target (per-MIR-op kernel-body @lowering on CUDA). It does NOT satisfy it for three other concerns.
The three problems addressed
SaTiledCartesian2Dop docstring IS the C++ template — it doesn't just encode the shape, it IS the shape).LoweringCtxholds ~15 CUDA-render scratch fields. Split into target-agnosticLowerCtx(5 fields, F3-pinned) + per-targetCudaRenderCtx. Rename CUDA-shaped IIR ops to semantic names.compile_kernel_body(ep, target='cuda')accepts the param but the rest of the pipeline hard-wires CUDA.Compiler.run(prog, target='cuda')+ multi-targettargets=['cuda', 'cpu_tbb']. Plugin discovery splits into[srdatalog.dialects](data) +[srdatalog.targets](render). R3 verify_renderability becomes per-target.Biggest surprises uncovered during diagnosis
ep_has_X(...)helpers are the bool-field anti-pattern reskinned. The parked A3-1/2/3 branches replaceif ep.dedup_hash:withif ep_has_pragma(ep, DedupHash):— same imperative branch, different key. Spec § 8.3 marks them as net-negative work post-redesign; Phase R deletes both bool reads AND helper reads in one shot.complete_runner.py:37literal cross-tree side-effect import to trigger CUDA plugin registration. Runner knows a specific data dialect by name. Worse coupling than the brief described.CodeGenContexthas 35+ fields.SaTiledCartesian2Dhas 20 fields and the op docstring IS the literal CUDA C++ template text atops.py:196-232. Not "encodes CUDA shape" — IS the CUDA shape rendered into the type system.view_counts_for_specsis consumed byEmitViewDeclsShimin the supposedly-target-agnostic kernel pipeline. Spec moves it into a CUDA-render-side pass.Per-PR partition
Expanded to 35 PRs (vs estimated 20-30) to preserve per-PR byte-equivalence gating:
Dependency that required care: T1 must precede R3 (RIR renders need per-target render-ctx); B2-1 must precede R3-8 (per-target render dispatch is what R3-8 deletes the monolith to use).
Framing tensions
register()form continues to work), but multi-target plugins need to split. Should Phase E be versioned E1 + E2? Spec recommends yes when Wave T3 lands; defers to reviewer.feature:blocked;migration:/refactor:exempt). Procedural rather than mechanical.Relationship to existing work
ep_has_X(...)helpers both disappear under Phase RTest plan
Why this is a DRAFT
Open as draft so you can review the spec before any subsequent migration PR references it. Conversion to ready-for-review happens after you sign off on:
🤖 Generated with Claude Code